package com.googlecode.gamedroid.sockethelper;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

import android.os.Build;

public class SocketNetwork implements ISocket
{
	private String mHost;
	private int mPort;
	private Socket mSocket = null;
	
	public SocketNetwork(String host, int port)
	{
		mHost = host;
		mPort = port;
	}
	
	@Override
	public void close() throws IOException
	{
		if(mSocket == null)
			throw new IOException();
		
		mSocket.shutdownInput();
		mSocket.shutdownOutput();
		mSocket.close();
	}
	
	@Override
	public void connect() throws IOException
	{
		mSocket = new Socket(mHost, mPort);
	}
	
	@Override
	public String getHostName()
	{
		return Build.MODEL;
	}
	
	@Override
	public InputStream getInputStream() throws IOException
	{
		if(mSocket == null)
			throw new IOException();
		return mSocket.getInputStream();
	}
	
	@Override
	public OutputStream getOutputStream() throws IOException
	{
		if(mSocket == null)
			throw new IOException();
		return mSocket.getOutputStream();
	}
}
